package cn.controller;

import cn.entity.Deliver;
import cn.entity.Firm;
import cn.entity.Post;
import cn.entity.User;
import cn.service.DeliverService;
import cn.service.FirmService;
import cn.service.PostService;
import cn.tool.Const;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Controller
@RequestMapping("/deliver")
public class DeliverController {

    @Autowired
    private DeliverService deliverService;
   //增加
    @RequestMapping("doadd")
    public String insertSelective(Deliver deliver){
       deliver.setResult("未通过");
       deliver.setAudit(0);
       deliver.setIsdel(0);
       int con=deliverService.insertSelective(deliver);
       if(con>0) {
    	   return "redirect:"+ Const.ROOT01+"panduan/getNotice";
       }else {
    	   return null;
       }
    }
    //修改
    @RequestMapping("doupdate")
	  public String updateByPrimaryKeySelective(Deliver deliver) {
		  deliver.setAudit(1);
		  deliver.setResult("已通过");
	      int con=deliverService.updateByPrimaryKeySelective(deliver);
	      if(con>0) {
	    	  return"redirect:"+Const.ROOT01+"deliver/getDeliver";
	      }else {
	    	  return null;
	      }
	  }
 
    @RequestMapping("getDeliver")
    public String getDeliver(String education,String post,HttpSession session,Model model){
    	//去session里面取
    	Object obj=session.getAttribute("user");
    	if(obj!=null){
	        String firm=((Firm)obj).getFirm();
	        Map<String,String> params=new HashMap<String,String>();
	        params.put("firm",firm);
	        params.put("education",education);
	        params.put("post",post);
	        List<Deliver> delivers=deliverService.getDeliver(params);
	        model.addAttribute("delivers",delivers);
	        model.addAttribute("education",education);
	        model.addAttribute("post",post);
    	}
        return "toudi";
    }
    
   
    @RequestMapping("getUserDeliver")
    public String getUserDeliver(HttpSession session,Model model) {
    	Integer user=((User)session.getAttribute("user")).getId();
    	List<Deliver> delivers=deliverService.getUserDeliver(user);
    	model.addAttribute("delivers",delivers);
    	return"liebiao";
    	
    }
    
    
}
